class Solution {
public:
    int calculate(int lef, int rig, int x)
    {
        int hh = lef > rig ? rig : lef;
        return hh * x;
    }
    int maxArea(vector<int>& height) {
        int len = height.size();
        int left = 0, right = len - 1;
        int tmparea = 0;
        int maxarea = calculate(height[left], height[right], right - left);
        //数组长度为2
        if (len == 2)
        {
            return maxarea;
        }
        while (left < right)
        {
            if (height[right] > height[left])
            {
                left++;
                tmparea = calculate(height[left], height[right], right - left);
                if (tmparea > maxarea)
                {
                    maxarea = tmparea;
                }
            }

            else
            {
                right--;
                tmparea = calculate(height[left], height[right], right - left);
                if (tmparea > maxarea)
                {
                    maxarea = tmparea;
                }
            }


        }
        return maxarea;
    }
};